home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / utilities / vt2tx.c < prev   
Encoding:
C/C++ Source or Header  |  1997-05-08  |  7.6 KB  |  210 lines

  1. #ifndef    lint
  2. static char SccsId[]= "@(#)vt2tx.c    V1.5    5/2/95";
  3. #endif
  4. /* ====================================================================
  5.    vt2tx - convert vector text fonts to hardware text in a viewfile
  6.    --------------------------------------------------------------------
  7.    VERSION        1.0
  8.    SYNOPSIS       vt2tx <device-string> <viewfile-source> <viewfile-destination> [<fontsize>]
  9.    DESCRIPTION    Converts all vector text fonts in a viewfile to hardware
  10.              text fonts. If the user specifies a fontsize (1,2,3, or 4)
  11.                   then the program will set the hardware font to that size.
  12.                   If no fontsize is specified, then the program uses the
  13.                   largest font that will fit in the same area when the
  14.                   view is drawn to the full screen.
  15.  
  16.                   Once the changes are made the user should be able to go into
  17.                   DV-Draw and make the appropriate fine changes if
  18.                   necessary.  The utility will correctly convert all
  19.                   vector texts in included subdrawings; referenced
  20.                   subdrawings will be left as is.
  21.  
  22.    HOW IT WORKS
  23.  
  24.        There are three possibilities requiring consideration in a
  25.    view when converting:
  26.  
  27.        (1) if it is a vector text object (OT_VTEXT):
  28.            (a) create a version in regular text (VOtxCreate);
  29.            (b) set the size to the user-specified value or if, no value
  30.                was specified, choose the largest font that will fit in
  31.                the space occupied by the vector font (VOtxAtSet)
  32.            (c) replace the vector text with the regular text.
  33.                (using VOdrObReplace).
  34.        (2) if it is a included subdrawing (OT_SUBDRAWING), recursively do a
  35.            TobForEachSubobject with the drawing object associated with
  36.            the subdrawing.
  37.        (3) if it is anything else, ignore it.
  38.  
  39.    EXAMPLE      vt2tx x:=640x480 dan.v out.v 2
  40.    ================================================================= */
  41.  
  42. #include "std.h"
  43. #include "dvstd.h"
  44. #include "dvtools.h"
  45. #include "dvGR.h"
  46. #include "VOstd.h"
  47. #include "VOfundecl.h"
  48. #include "Tfundecl.h"
  49. #include "GRfundecl.h"
  50.  
  51. /* Global forward function declarations */
  52. ADDRESS ReplaceVtextWithText V_P_ ((OBJECT object, OBJECT ParentDrawing));
  53.  
  54. /* Local forward function declarations */
  55.  
  56. DRAWPORT drawport;
  57. INT text_size = 0, largest_text_size = 0;
  58. OBJECT DefaultTextBackcolor = 0;
  59.  
  60. LOCAL CHAR ErrMsg[]= "Wrong number of arguments.\n";
  61. LOCAL CHAR Usage[]= "Usage: %s <device-string> <viewfile-source> <viewfile-destination> [<textsize>]\n";
  62. LOCAL CHAR *DVpath = NULL;      /* Use value of DVPATH config variable */
  63.  
  64. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  65.                      LPSTR lpCmdLine,  int nCmdShow  )
  66.  {
  67.   VIEW view;
  68.   SCREEN_OBJECT screen;
  69.   OBJECT ParentDrawing; 
  70.   int argc = 0;
  71.   char **argv;
  72.  
  73.   make_argv(&argc,&argv,GetCommandLine()); 
  74.  
  75.   /* Make sure there are at least 3 arguments */
  76.   if (argc < 4)
  77.     {
  78.       (VOID) fprintf (stderr, ErrMsg);
  79.       (VOID) fprintf (stderr, Usage, argv[0]);
  80.       exit (EXIT_ERR);
  81.     }
  82.  
  83.   /* Initialize program */
  84.   (VOID) TInit (DVpath, (CHAR *) NULL);
  85.   screen = TscOpen (argv[1], (CHAR *) NULL);
  86.   view = TviLoad (argv[2]);
  87.   drawport = TdpCreate (screen, view, (RECTANGLE *) NULL,
  88.                         (RECTANGLE *) NULL);
  89.  
  90.   /* Get arguments for traversal function, ReplaceVtextWithText. */
  91.   GRget (V_NUM_FONTS, &largest_text_size, V_END_OF_LIST);
  92.   ParentDrawing = TviGetDrawing (view);
  93.   if (argc >= 5)
  94.     {                           /* Get text size to use. */
  95.       (VOID) sscanf (argv[4], "%d", &text_size);
  96.       text_size = S_MAX (1, text_size);
  97.       text_size = S_MIN (largest_text_size, text_size);
  98.     }
  99.  
  100.   DefaultTextBackcolor = VOcoCreate (COLOR_NAME, "black");
  101.  
  102.   /* Recursively replace all regular text object */
  103.   (VOID) TobForEachSubobject (ParentDrawing,
  104.                   (TOBFOREACHSUBOBJFUNPTR)ReplaceVtextWithText,
  105.                               (ADDRESS) ParentDrawing);
  106.  
  107.   /* Save new view file and clean-up */
  108.   if (!TviSave (view, argv[3]))
  109.     (VOID) fprintf (stderr, "%s: Could not save view\n", argv[3]);
  110.   TdpFree (drawport);
  111.   (VOID) TscClose (screen);
  112.   (VOID) TTerminate ();
  113.   return EXIT_OK;
  114. }
  115.  
  116. /* ********************************************************************** */
  117. /* Function that replaces vector text object with regular text equivalent */
  118. ADDRESS 
  119. ReplaceVtextWithText (object, ParentDrawing)
  120.      OBJECT object;
  121.      OBJECT ParentDrawing;
  122. {
  123.   INT obtype, text_size_guess, text_direction, width, height;
  124.   OBJECT ptobj, txobj, NewParentDrawing;
  125.   DV_POINT vtsize;
  126.   ATTRIBUTES attr;
  127.   RECTANGLE wvp, pixoffset, svp;
  128.   CHAR *string;
  129.  
  130.   /* If it is of vector text type replace it with regular text,
  131.      else if it is an included subdrawing, descend recursively and repeat,
  132.      else just ignore.  */
  133.   obtype = VOobType (object);
  134.   if (obtype == OT_VTEXT)
  135.     {
  136.       /* construct a close match of vector text with regular text */
  137.       ptobj = VOobPtGet (object, 1);
  138.       VOobAtGet (object, &attr);
  139.  
  140.       /* Make sure there is a background color */
  141.       if (attr.background_color == EMPTY_FIELD)
  142.         attr.background_color = DefaultTextBackcolor;
  143.  
  144.       string = VOvtGetString (object);
  145.  
  146.       /* Calculate the text size */
  147.       if (text_size > 0)
  148.         {                       /* User specified the text size */
  149.           attr.text_size = text_size;
  150.         }
  151.       else
  152.         {                       /* Make a best guess about the text size */
  153.  
  154.           /* Calculate the size of the vector text in screen coordinates */
  155.           VOobBox (object, &wvp, &pixoffset);
  156.           (VOID) TdpWorldToScreen (drawport, &wvp.ll, &svp.ll);
  157.           (VOID) TdpWorldToScreen (drawport, &wvp.ur, &svp.ur);
  158.           svp.ll.x += pixoffset.ll.x;
  159.           svp.ll.y += pixoffset.ll.y;
  160.           svp.ur.x += pixoffset.ur.x;
  161.           svp.ur.y += pixoffset.ur.y;
  162.           vtsize.x = 1 + S_ABS (svp.ur.x - svp.ll.x);
  163.           vtsize.y = 1 + S_ABS (svp.ur.y - svp.ll.y);
  164.  
  165.           /* Choose the largest hardware font that fits */
  166.           if (attr.text_direction == VERTICAL_TEXT)
  167.             text_direction = VERTICAL_TEXT;
  168.           else
  169.             text_direction = HORIZONTAL_TEXT;
  170.  
  171.           for (text_size_guess = largest_text_size;
  172.                text_size_guess > 0;
  173.                text_size_guess--)
  174.             {
  175.               VOgChSize (text_size_guess);
  176.               VOgTextsize (string, text_direction, &width, &height);
  177.               if (width <= vtsize.x && height <= vtsize.y)
  178.                 break;
  179.             }
  180.  
  181.           if (text_size_guess <= 0)
  182.             text_size_guess = 1;
  183.  
  184.           /* Now set the size */
  185.           attr.text_size = text_size_guess;
  186.         }
  187.  
  188.       txobj = VOtxCreate (string, ptobj, &attr);
  189.  
  190.       /* Make sure slots get copied over */
  191.       /* This assumes dynamics are kept in slots and will be copied properly */
  192.       VOobCopySlots (txobj, object);
  193.  
  194.       (VOID) VOdrObReplace (ParentDrawing, object, txobj);      /* replace! */
  195.     }
  196.   else if (obtype == OT_SUBDRAWING)
  197.     {
  198.       /* We are looking at a subdrawing. If the subdrawing is included, then
  199.          descend recursively and search again for regular text to replace */
  200.       if (VOsdViKeep (object, -1 /* Invalid value */ ))
  201.         {
  202.           NewParentDrawing = VOsdDrGet (object);
  203.           (VOID) TobForEachSubobject (NewParentDrawing,
  204.                  (TOBFOREACHSUBOBJFUNPTR)ReplaceVtextWithText,
  205.                                  (ADDRESS) NewParentDrawing);
  206.         }
  207.     }
  208.   return NULL;
  209. }
  210.